const config = include('/config');

const config_name = process.env.CONFIG;
const db_config = config[config_name];

const isIM = function() {
  return ['im', 'im_dev'].includes(config_name);
};

const isPaopai = function() {
  return ['paopai', 'local', 'paopai_dev'].includes(config_name);
};

const getIMDatabase = function() {
  return [
    { type: 'mongodb', url: db_config.business, name: 'business' },
    { type: 'mongodb', url: db_config.statistics, name: 'statistics' },
  ];
};

const getPaopaiDatabase = function() {
  return [
    { type: 'mysql', url: db_config.business, name: 'business' },
    { type: 'mongodb', url: db_config.statistics, name: 'statistics' },
  ];
};

const SystemStatus = {
  isIM: isIM,
  isPaopai: isPaopai,
  getDatabase: function() {
    if (isIM()) return getIMDatabase();
    if (isPaopai()) return getPaopaiDatabase();
  },
};

module.exports = SystemStatus;
